<?php
namespace Admin\Controller;
use Think\Controller;
class PartnerController extends CommonController {

	public function index(){
		$M = M("Partner");

        $count = $M->where($map)->count();
        $Page       = new \Think\Page($count,25);
        $showPage = $Page->show();
        $this->assign("page", $showPage);

        $list = $M->where($map)->order('sort ASC, id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
        foreach ($list as $key => $val) {

        }
        $this->assign('list',$list);
		$this->display('partner');
	}

	public function add(){
		if(IS_POST){
			$data = array();
			$id = I('post.id');
			$data = I('post.data');
			$data['name'] = trim($data['name']);
			$data['update_time'] = NOW_TIME;

			$M = M('Partner');
			if($id){
				$M->where( array('id'=>$id) )->save($data);
				$result = array('status'=>1, 'info'=>'更新成功！', 'url'=>U('Partner/index'));
			}else{
				$data['create_time'] = NOW_TIME;
				$M->add($data);
				$result = array('status'=>1, 'info'=>'添加成功！', 'url'=>U('Partner/index'));
			}
			$this->ajaxReturn($result);
			exit;
		}

		$id = I('get.id');
		if($id){
			$M = M('Partner');
			$info = $M->where('id='.$id)->find();
			$this->assign('info',$info);
		}
		$this->display();
	}

	public function change(){
		$Partner = M('Partner');
		$id = I('post.id');
		$fd = I('post.fd');
		$value = I('post.value');
		$Partner->where( array('id'=>$id) )->setField($fd,$value);
	}

	public function del(){
		$Partner = M("Partner");
		$ids = I('get.id');

		$map['id'] = array('in',$ids);
		$Partner->where( $map )->delete();
        $result = array('status'=>1, 'info'=>'成功删除！', 'url'=>U('Partner/index'));
        $this->ajaxReturn($result);
		exit;
	}

	public function opRoleStatus(){
		$status = I('get.status');
		$data['id'] = I('get.id');
		$data['status'] = $status==1?0:1;
		M("Partner")->save($data);
		$result = array('status'=>1, 'info'=>'操作成功！');
        $this->ajaxReturn($result);
		exit;
	}

}